//
//  WCBOrderInfoCell.m
//  WeChatBuniess
//
//  Created by Guo Rui on 2017/12/19.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "WCBOrderInfoCell.h"

@interface WCBOrderInfoCell()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *bookTitleLabel;
@property (strong, nonatomic) UILabel *bookCoverInfoLabel;
@property (strong, nonatomic) UILabel *bookPageInfoLabel;
@property (strong, nonatomic) UILabel *bookPageCountLabel;
@property (strong, nonatomic) UILabel *bookDateLabel;
@end

@implementation WCBOrderInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setBookModel:(WCBWeChatBookModel *)bookModel
{
    _bookModel = bookModel;
    
    self.bookTitleLabel.text = [NSString stringWithFormat:@"《%@》", bookModel.title];
    self.bookCoverInfoLabel.text = [NSString stringWithFormat:@"封面: %@", bookModel.bookCoverInfo];
    self.bookPageInfoLabel.text = [NSString stringWithFormat:@"内页: %@", bookModel.bookPageInfo];
    self.bookPageCountLabel.text = [NSString stringWithFormat:@"页数: %@页", bookModel.pageSize];
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy.MM";
    NSString *startDate = [fmt stringFromDate:[NSDate dateWithTimeIntervalSince1970:bookModel.startDate.floatValue / 1000]];
    NSString *endDate = [fmt stringFromDate:[NSDate dateWithTimeIntervalSince1970:bookModel.endDate.floatValue / 1000]];
    self.bookDateLabel.text = [NSString stringWithFormat:@"成书时间: %@~%@", startDate, endDate];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat x, y, w, h;
    CGFloat width = CGRectGetWidth(self.contentView.frame);
    
    {
        x = 30.f;
        y = 15.f;
        w = width - 2 * x;
        h = 45.f;
        self.titleLabel.frame = CGRectMake(x, y, w, h);
    }
    
    
    {
        x = 20.f;
        y = CGRectGetMaxY(self.titleLabel.frame) + 15.f;
        w = width - 2 * x;
        h = 40.f;
        self.bookTitleLabel.frame = CGRectMake(x, y, w, h);
    }
    
    
    {
        x = 30.f;
        y = CGRectGetMaxY(self.bookTitleLabel.frame) + 10.f;
        w = width / 2.f - 2 * x;
        h = 40.f;
        self.bookCoverInfoLabel.frame = CGRectMake(x, y, w, h);
    }
    
    {
        x = width / 2.f;
        y = CGRectGetMinY(self.bookCoverInfoLabel.frame);
        w = width - x;
        h = 40.f;
        self.bookPageInfoLabel.frame = CGRectMake(x, y, w, h);
    }
    
    {
        x = 30.f;
        y = CGRectGetMaxY(self.bookCoverInfoLabel.frame) + 10.f;
        w = width / 2.f - x;
        h = 40.f;
        self.bookPageCountLabel.frame = CGRectMake(x, y, w, h);
    }
    
    {
        x = width / 2.f;
        y = CGRectGetMaxY(self.bookCoverInfoLabel.frame) + 10.f;
        w = width - width / 2.f;
        h = 40.f;
        self.bookDateLabel.frame = CGRectMake(x, y, w, h);
    }
}

#pragma mark - Getter
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:24];
        _titleLabel.text = @"订单信息";
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)bookTitleLabel
{
    if (!_bookTitleLabel) {
        _bookTitleLabel = [[UILabel alloc] init];
        _bookTitleLabel.textColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.00];
        _bookTitleLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_bookTitleLabel];
    }
    return _bookTitleLabel;
}

- (UILabel *)bookCoverInfoLabel
{
    if (!_bookCoverInfoLabel) {
        _bookCoverInfoLabel = [[UILabel alloc] init];
        _bookCoverInfoLabel.textColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.00];
        _bookCoverInfoLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_bookCoverInfoLabel];
    }
    return _bookCoverInfoLabel;
}

- (UILabel *)bookPageInfoLabel
{
    if (!_bookPageInfoLabel) {
        _bookPageInfoLabel = [[UILabel alloc] init];
        _bookPageInfoLabel.textColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.00];
        _bookPageInfoLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_bookPageInfoLabel];
    }
    return _bookPageInfoLabel;
}

- (UILabel *)bookPageCountLabel
{
    if (!_bookPageCountLabel) {
        _bookPageCountLabel = [[UILabel alloc] init];
        _bookPageCountLabel.textColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.00];
        _bookPageCountLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_bookPageCountLabel];
    }
    return _bookPageCountLabel;
}

- (UILabel *)bookDateLabel
{
    if (!_bookDateLabel) {
        _bookDateLabel = [[UILabel alloc] init];
        _bookDateLabel.textColor = [UIColor colorWithRed:0.20 green:0.20 blue:0.20 alpha:1.00];
        _bookDateLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_bookDateLabel];
    }
    return _bookDateLabel;
}

@end
